package com.wwp.tbshop.accout_center.presenter;

import android.widget.Toast;

import com.wwp.tbshop.accout_center.fragment.Login_frament;
import com.wwp.tbshop.model.bean.BaseBean;
import com.wwp.tbshop.model.bean.LoginBean;
import com.wwp.tbshop.presenter.BasePresenter;
import com.wwp.tbshop.util.UiUtil;

import retrofit2.Call;

/**
 * Created by Administrator on 6/17/2017.
 */

public class Login_presenter extends BasePresenter {

    private Login_frament mLogin_frament;

    public Login_presenter(Login_frament login_frament) {
        mLogin_frament = login_frament;
    }


    public void LoginUserNewsInfo(String username, String password) {
        Call<LoginBean> userInfoBeanCall = mApiService.login(username, password);
        userInfoBeanCall.enqueue(mCallback);
    }


    @Override
    protected void onServerBug(int code) {

    }

    @Override
    protected void onConnectError(String message) {

    }

    @Override
    protected void onSuccess(BaseBean baseBean) {
        String error_code = baseBean.getError_code();

        //用户名不存在或密码错误

        // 正确时error_code 为null
        if (error_code != null) {

            switch (error_code) {
                case "1530":
                    Toast.makeText(UiUtil.sContext, baseBean.getError(), Toast.LENGTH_SHORT).show();
                    return;
                case "1532":
                    Toast.makeText(UiUtil.sContext, baseBean.getError(), Toast.LENGTH_SHORT).show();
                    return;
                case "1534":
                    Toast.makeText(UiUtil.sContext, baseBean.getError(), Toast.LENGTH_SHORT).show();
                    return;
                case "error":
                    Toast.makeText(UiUtil.sContext, baseBean.getError(), Toast.LENGTH_SHORT).show();
                    return;
            }
        }

        LoginBean loginBean = (LoginBean) baseBean;
        mLogin_frament.loginSuccess(loginBean);

    }


}
